## palette MM Likert outcome using only black respondents
##
## August 5, 2019
##
## Kevin Quinn
## University of Michigan
##

library(MCMCpack)
set.seed(377599)

mydata <- read.csv("../ScaleRaceSpring2017clean.csv")

## subset data
mydata <- mydata[mydata$R.race == "Black",]
mydata <- mydata[!is.na(mydata$R.race),]


## keep responses and photo IDs but nothing else
inds <- 1:24
keep.vars <- c(paste("X", inds, "_Q329", sep=""),
               paste("X", inds, "a.id", sep=""))

mydata.sub <- mydata[, keep.vars]


## reshape into long format
mydata.sub.long <- reshape(mydata.sub, direction="long",
                           varying=list(c(1:24), c(25:48)),
                           v.names=c("Y", "photoID"),
                           ids=rownames(mydata.sub))

## keep only obs with non-missing values for MM
mydata.sub.long <- na.omit(mydata.sub.long)

mydata.sub.long <- mydata.sub.long[sample(1:nrow(mydata.sub.long),
                                          size=1000, replace=FALSE),]


cat("\n\nN =", nrow(mydata.sub.long), "\n\n") 


a3.M2.out <- MCMCoprobit(Y ~ as.factor(photoID), data=mydata.sub.long,
                         burnin=50000, mcmc=1000000, thin=50, tune=0.065,
                         verbose=10000, seed=666239
                         )


save(a3.M2.out, file="MM3.2.a3.M2.out.Rda")
